<?php
class Shop_Form_Product_Edit extends Shop_Form_Product_Add {
	public function init() {
		parent::init();
		
		$pk = $this->getPrimaryKey();
		
		$product = new Shop_Model_Product();
		$value = $product->getAttachedCategoriesId($pk);

		$this->getSubForm('categorytab')
			 ->getElement('tree')
			 ->setValue($value);

		$this->_addImageGrid();
	}
	
	public function _addImageGrid()
	{
		$datagrid = new KontorX_Form_Element_DataGrid('imageslist');

        $image = new Shop_Model_Image();
        $pk = $this->getPrimaryKey();

        $datagrid->setModel($image->selectListForProductPK($pk));
        $grid = $datagrid->getDataGrid();
        
        $renderer = new KontorX_DataGrid_Renderer_HtmlTable();
		$renderer->setModule('scaffold');
		$renderer->setPartial('_partial/dataGrid.phtml');
        $grid->setRenderer($renderer);

        $grid->setColumns(array(
//        	'id' => array(
//        		'options' => array(
//        			'displayNone' => 1
//        		),
//        		'cell' => array(
//        			'type' => 'Editable_FormCheckbox',
//        			'options' => array(
//        				'primaryKey' => 'id'
//        			)
//        		),
//        	),
        	'image' => array(
        		'type' => 'Text',
        		'name' => 'Grafika',
        		'cell' => new Promotor_DataGrid_Cell_ImageEditor(array(
        			'src' => 'upload/shop/product/small/',
        			'srcFull' => 'upload/shop/product/'
        		))
        	),
        	'main_image' => array(
        		'type' => 'Text',
        		'name' => 'Główna',
        		'cell' => array(
        			'type' => 'Editable_FormRadio',
        			'options' => array(
        				'primaryKey' => 'id'
        			)
        		)
        	),
        	'delete' => array(
        		'type' => 'Text',
        		'options' => array(
        			'style' => 'width:20px;',
        			'displayNone' => 1
        		),
        		'cell' => array(
        			'type' => 'Url',
        			'options' => array(
        				'name' => 'Usuń',
        				'class' => 'action trash ico',
        				'target' => '_blank',
	        			'action' => 'delete',
        				'controller' => 'image',
        				'primaryKey' => 'id'
        			)
        		)
        	)        		
        ));

        $this->getSubForm('imagetab')->addElement($datagrid);
	}
}